<?php
/**
 * The control file of index module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class index extends control
{
	private $_yzcode;
    protected $sysmanage;
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->sysmanage=$this->loadModel('sysmanage');
		$this->updateopt=$this->loadModel('updateopt');
		
	}

    /**
     * The index page.
     * 
     * @access public
     * @return void
     */
    public function index()
    {
        $this->view->title = $this->lang->welcome;
        $this->display();
    }
    /**
     * 文档类
     */
    // public function doc()
    // {
    	// $this->display();
    // }
	/**
     * IPv6-首页类
     */
    public function ipv6($key_words='')
    {
		//var_dump($key_words);
		$where=new stdClass();
        $where->key_words=$key_words;
		$this->view->sites_info_list = $this->index->get_info($where);
		//var_dump($this->view->sites_info_list);
		$this->display();	
    }
	/**
     * 升级网站名称类
     */
    public function ipv6_update_net($key_words='')
    {
		//var_dump($key_words);
		$where=new stdClass();
        $where->key_words=$key_words;
		$this->view->sites_info_list = $this->index->get_info($where);
		//var_dump($this->view->sites_info_list);
		//echo count($this->view->sites_info_list);
		//echo json_encode($this->view->sites_info_list);
    	$this->display();
    }
	/**
     * IPv6相关测试类
     */
    public function ipv6_test()
    {
    	$this->display();
    }
	/**
     * 链接状态类
     */
    public function ipv6_net_name($type_id='all',$unit_id='all',$area_id='all',$ipv6_status='all')
    {	
		if(!empty($_POST)){
			if($_POST["type_id"]==''){
				$type_id = 'all';
			}else{
				$type_id=$_POST["type_id"];
			}
			if($_POST["unit_id"]==''){
				$unit_id = 'all';
			}else{
				$unit_id=$_POST["unit_id"];
			}
			if($_POST["area_id"]==''){
				$area_id = 'all';
			}else{
				$area_id=$_POST["area_id"];
			}
		}
		//得到所有网站类型
    	$this->view->type_info=$this->updateopt->get_type_info();
    	//得到所有网站区域
    	$where_area=new stdClass();
    	$where_area->reid=0;
    	$this->view->area_info=$this->updateopt->get_area_info(null,$where_area);
    	//得到所有单位
    	$this->view->unit_info=$this->updateopt->get_unit_info();

		$where=new stdClass();	
        $where->type_id=$type_id;
        $where->area_id=$area_id;
        $where->unit_id=$unit_id;   
        $where->visit_type=$visit_type;   
        $where->pre_v6=$pre_v6;   
        $where->ipv6_status=$ipv6_status;
		$this->view->sites_info_list = $this->index->get_sites_info($where);
		//echo json_encode($this->view->sites_info_list);
    	//$this->view->sites_info_list=$this->dao->select('*')->from('sites_info')->fetchAll();
    	//$data=$this->dao->select('type_name')->from('type_info')->where("type_id=1")->fetch();
		//var_dump($data);
		//var_dump($this->view->sites_info_list);	
		$this->display();	
    }
	/**
     * FAQ页面展示
     */
    public function FAQ()
    {
    	$this->display();
    }
	/**
     * 案例展示
     */
    // public function ipv6case()
    // {
    	// $this->display();
    // }
    /**
     * 得到省级升级排序
     */
    public function getShengSort(){
    	$result=$this->index->get_sheng_sort();
    	$returnarr=array();
    	foreach($result as $key=>&$val){
    		if($val->name!=null&&$val->name!=''){
    			$returnarr[]=$val;
    		}
    	}
    	echo json_encode($returnarr);
    }
    /**
     * 得到市级排序
     */
    public function getShiSort(){
    	$shengtitle=$_POST['shengtitle'];
    	$result=$this->index->get_shi_sort($shengtitle);
    	$returnarr=array();
    	foreach($result as $key=>&$val){
    		if($val->name!=null&&$val->name!=''){
    			$returnarr[]=$val;
    		}
    	}
    	echo json_encode($returnarr);
    	
    }
	/**
     * 得到IP地址
     */
	public function get_IP(){
		function getIP() /*获取客户端IP*/
		{
		if (@$_SERVER["HTTP_X_FORWARDED_FOR"])
		$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
		else if (@$_SERVER["HTTP_CLIENT_IP"])
		$ip = $_SERVER["HTTP_CLIENT_IP"];
		else if (@$_SERVER["REMOTE_ADDR"])
		$ip = $_SERVER["REMOTE_ADDR"];
		else if (@getenv("HTTP_X_FORWARDED_FOR"))
		$ip = getenv("HTTP_X_FORWARDED_FOR");
		else if (@getenv("HTTP_CLIENT_IP"))
		$ip = getenv("HTTP_CLIENT_IP");
		else if (@getenv("REMOTE_ADDR"))
		$ip = getenv("REMOTE_ADDR");
		else
		$ip = "Unknown";
		return $ip;
		}
		echo getIP();
	}
   /**
     * 升级检测
     */
    // public function upcheck()
    // {
    	// $this->display();
    // }
 	/**
     * 网站检测
     */
    public function check_url(){
    	$checkurl=$_POST['checkurl'];
    	$this->updateopt=$this->loadModel('updateopt');
    	$data_ipv6=$this->updateopt->test_url($checkurl,'ipv6');
    	echo json_encode($data_ipv6);
    }
    /**
     * 用户登录
     */
    public function login(){
        $this->display();
    }
    public function make_code(){
       $this->_yzcode=$this->app->loadClass('yzcode');
       echo $this->_yzcode;
    }
    
    /**
     * 用户登录检测
     */
    public function check_login(){
    	//验证码检测，先去掉
        /*if(!$this->index->check_word($_POST['yzcode'])){
           echo '';
        }*/
        $user = $this->index->check_login($_POST['username'],$_POST['password']);
        if($user){
           if($user->status==0){//用户被禁用
              echo 'forbidden';
              exit();
           }
           $_SESSION['username']=$user->username;
           $_SESSION['userid']=$user->userid;
           $this->sysmanage->set_optlog('用户登录成功：'.$user->username);
           echo 'success';
        }else{
           echo "failure";//用户名或密码错误
        }
    }
    /**
     * 用户退出
     */
    public function logout(){
      unset($_SESSION['username']);
      unset($_SESSION['userid']);
      $this->locate($this->createLink('index','login'));
    }
}
